﻿ using LockheedMartin.Prepar3D.SimConnect;
using System;
using System.Collections.Generic;
using System.Configuration;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Interop;
using System.Windows.Threading;

namespace SimWithP3d.Vehicle
{
    /// <summary>
    /// 使用simconnect 控件飞机相关
    /// </summary>
    public class SimControlAircraft
    {
        public static SimConnect simConnect = null;
        /// <summary>
        /// 事件ID
        /// </summary>
        enum EVENTS
        {
            #region adjustGague
            //空速表
            TRUE_AIRSPEED_CAL_INC,
            TRUE_AIRSPEED_CAL_DEC,
            //VACUUM
            GYRO_DRIFT_INC,
            GYRO_DRIFT_DEC,
            HEADING_BUG_INC,
            HEADING_BUG_DEC,
            //高度表
            KOHLSMAN_INC,
            KOHLSMAN_DEC,
            //OBS1
            VOR1_OBI_INC,
            VOR1_OBI_DEC,
            //OBS2
            VOR2_OBI_INC,
            VOR2_OBI_DEC,
            //ADF
            ADF_CARD_INC,
            ADF_CARD_DEC,
            #endregion


            #region R22
            MARKER_SOUND_TOGGLE,//MKR
            GPS_NEAREST_BUTTON,//GPS NRST
            GPS_OBS_BUTTON,//GPS OBS
            GPS_MSG_BUTTON,//GPS MSG
            GPS_FLIGHTPLAN_BUTTON,//GPS FPL
            GPS_TERRAIN_BUTTON,//TERR
            GPS_PROCEDURE_BUTTON,//PROC
            GPS_ZOOMOUT_BUTTON,//上
            GPS_ZOOMIN_BUTTON,//下
            GPS_DIRECTTO_BUTTON,// diector
            GPS_MENU_BUTTON,//MENU
            GPS_CLEAR_BUTTON,//CLR
            GPS_ENTER_BUTTON,//ENT
            GPS_CURSOR_BUTTON,//PUSH CRSR
            GPS_GROUP_KNOB_DEC,//外圈左
            GPS_GROUP_KNOB_INC,//外圈右
            GPS_PAGE_KNOB_DEC,//内圈左
            GPS_PAGE_KNOB_INC,//内圈右
            COMNAV1,//COM NAV 频率加减
            COMNAV2,
            COMNAV3,
            COMNAV4,
            ENGINE_AUTO_START,//点火
            ENGINE_AUTO_SHUTDOWN,//熄火
            #endregion

            #region 教员站Task And View界面
            SITUATION_RESET,//重载
            ELECTRIC_GPU_SWITCH_TOGGLE,//电源重置

            VIEW_MODE,//视角切换 S键
            NEXT_SUB_VIEW,//视角切换 A键
            VIEW_COCKPIT_FORWARD,//F10视角第一视角
            VIEW_VIRTUAL_COCKPIT_FORWARD,//F9视角舱内第一视角
            #endregion
        }
        /// <summary>
        /// 连接p3d
        /// </summary>
        public static void connectP3d()
        {
            try
            {
                if (simConnect != null)
                    simConnect.Dispose();
                simConnect = null;
                simConnect = new SimConnect("Connect P3d", IntPtr.Zero, 0, null, 0);//连接p3d

                #region adjustGague 事例初始声明
                simConnect.MapClientEventToSimEvent(EVENTS.TRUE_AIRSPEED_CAL_INC, "TRUE_AIRSPEED_CAL_INC");
                simConnect.MapClientEventToSimEvent(EVENTS.TRUE_AIRSPEED_CAL_DEC, "TRUE_AIRSPEED_CAL_DEC");
                simConnect.MapClientEventToSimEvent(EVENTS.GYRO_DRIFT_INC, "GYRO_DRIFT_INC");
                simConnect.MapClientEventToSimEvent(EVENTS.GYRO_DRIFT_DEC, "GYRO_DRIFT_DEC");
                simConnect.MapClientEventToSimEvent(EVENTS.HEADING_BUG_INC, "HEADING_BUG_INC");
                simConnect.MapClientEventToSimEvent(EVENTS.HEADING_BUG_DEC, "HEADING_BUG_DEC");
                simConnect.MapClientEventToSimEvent(EVENTS.KOHLSMAN_INC, "KOHLSMAN_INC");
                simConnect.MapClientEventToSimEvent(EVENTS.KOHLSMAN_DEC, "KOHLSMAN_DEC");
                simConnect.MapClientEventToSimEvent(EVENTS.VOR1_OBI_INC, "VOR1_OBI_INC");
                simConnect.MapClientEventToSimEvent(EVENTS.VOR1_OBI_DEC, "VOR1_OBI_DEC");
                simConnect.MapClientEventToSimEvent(EVENTS.VOR2_OBI_INC, "VOR2_OBI_INC");
                simConnect.MapClientEventToSimEvent(EVENTS.VOR2_OBI_DEC, "VOR2_OBI_DEC");
                simConnect.MapClientEventToSimEvent(EVENTS.ADF_CARD_INC, "ADF_CARD_INC");
                simConnect.MapClientEventToSimEvent(EVENTS.ADF_CARD_DEC, "ADF_CARD_DEC");
                #endregion

                #region R22事件初始声明
                if (ConfigurationManager.AppSettings["aircraftType"] == "R22")
                {
                    simConnect.MapClientEventToSimEvent(EVENTS.ENGINE_AUTO_START, "ENGINE_AUTO_START");
                    simConnect.MapClientEventToSimEvent(EVENTS.ENGINE_AUTO_SHUTDOWN, "ENGINE_AUTO_SHUTDOWN");
                    simConnect.MapClientEventToSimEvent(EVENTS.MARKER_SOUND_TOGGLE, "MARKER_SOUND_TOGGLE");
                    simConnect.MapClientEventToSimEvent(EVENTS.COMNAV1, "COM_RADIO_FRACT_DEC_CARRY");
                    simConnect.MapClientEventToSimEvent(EVENTS.COMNAV2, "COM_RADIO_FRACT_INC_CARRY");
                    simConnect.MapClientEventToSimEvent(EVENTS.COMNAV3, "NAV1_RADIO_FRACT_INC_CARRY");
                    simConnect.MapClientEventToSimEvent(EVENTS.COMNAV4, "NAV1_RADIO_FRACT_DEC_CARRY");
                    simConnect.MapClientEventToSimEvent(EVENTS.GPS_NEAREST_BUTTON, "GPS_NEAREST_BUTTON");
                    simConnect.MapClientEventToSimEvent(EVENTS.GPS_FLIGHTPLAN_BUTTON, "GPS_FLIGHTPLAN_BUTTON");
                    simConnect.MapClientEventToSimEvent(EVENTS.GPS_OBS_BUTTON, "GPS_OBS_BUTTON");
                    simConnect.MapClientEventToSimEvent(EVENTS.GPS_MSG_BUTTON, "GPS_MSG_BUTTON");
                    simConnect.MapClientEventToSimEvent(EVENTS.GPS_TERRAIN_BUTTON, "GPS_TERRAIN_BUTTON");
                    simConnect.MapClientEventToSimEvent(EVENTS.GPS_PROCEDURE_BUTTON, "GPS_PROCEDURE_BUTTON");
                    simConnect.MapClientEventToSimEvent(EVENTS.GPS_ZOOMOUT_BUTTON, "GPS_ZOOMOUT_BUTTON");
                    simConnect.MapClientEventToSimEvent(EVENTS.GPS_ZOOMIN_BUTTON, "GPS_ZOOMIN_BUTTON");
                    simConnect.MapClientEventToSimEvent(EVENTS.GPS_DIRECTTO_BUTTON, "GPS_DIRECTTO_BUTTON");
                    simConnect.MapClientEventToSimEvent(EVENTS.GPS_MENU_BUTTON, "GPS_MENU_BUTTON");
                    simConnect.MapClientEventToSimEvent(EVENTS.GPS_CLEAR_BUTTON, "GPS_CLEAR_BUTTON");
                    simConnect.MapClientEventToSimEvent(EVENTS.GPS_ENTER_BUTTON, "GPS_ENTER_BUTTON");
                    simConnect.MapClientEventToSimEvent(EVENTS.GPS_CURSOR_BUTTON, "GPS_CURSOR_BUTTON");
                    simConnect.MapClientEventToSimEvent(EVENTS.GPS_GROUP_KNOB_DEC, "GPS_GROUP_KNOB_DEC");
                    simConnect.MapClientEventToSimEvent(EVENTS.GPS_GROUP_KNOB_INC, "GPS_GROUP_KNOB_INC");
                    simConnect.MapClientEventToSimEvent(EVENTS.GPS_PAGE_KNOB_DEC, "GPS_PAGE_KNOB_DEC");
                    simConnect.MapClientEventToSimEvent(EVENTS.GPS_PAGE_KNOB_INC, "GPS_PAGE_KNOB_INC");
                }
                #endregion

                #region 教员站Task And View界面
                simConnect.MapClientEventToSimEvent(EVENTS.SITUATION_RESET, "SITUATION_RESET");
                simConnect.MapClientEventToSimEvent(EVENTS.ELECTRIC_GPU_SWITCH_TOGGLE, "ELECTRIC_GPU_SWITCH_TOGGLE");
                simConnect.MapClientEventToSimEvent(EVENTS.VIEW_MODE, "VIEW_MODE");
                simConnect.MapClientEventToSimEvent(EVENTS.NEXT_SUB_VIEW, "NEXT_SUB_VIEW");
                simConnect.MapClientEventToSimEvent(EVENTS.VIEW_COCKPIT_FORWARD, "VIEW_COCKPIT_FORWARD");
                simConnect.MapClientEventToSimEvent(EVENTS.VIEW_VIRTUAL_COCKPIT_FORWARD, "VIEW_VIRTUAL_COCKPIT_FORWARD");
                #endregion

                simConnect.AddClientEventToNotificationGroup(SIMCONNECT_DATA_SET_FLAG.DEFAULT, SIMCONNECT_EVENT_FLAG.DEFAULT, false);//事例加入组

            }
            catch (Exception ex)
            {
                if (simConnect != null)
                    simConnect.Dispose();
                simConnect = null;
                Console.WriteLine(ex.ToString());
            }
        }
        #region adjustGague 仪表按钮调整
        /// <summary>
        /// 仪表按钮调整事件写入 空速表 Vaccum 高度表 NAV1 NAV2 ADF
        /// </summary>
        /// <param name="evenID">事件ID</param>
        public static void simAdjustGague(string evenID)
        {

            try
            {
                switch (evenID)
                {
                    case "airspeed_INC": //空速表+
                        simConnect.TransmitClientEvent(SimConnect.SIMCONNECT_OBJECT_ID_USER, EVENTS.TRUE_AIRSPEED_CAL_INC, 0, SIMCONNECT_DATA_SET_FLAG.DEFAULT, SIMCONNECT_EVENT_FLAG.DEFAULT);
                        break;
                    case "airspeed_DEC":// 空速表-
                        simConnect.TransmitClientEvent(SimConnect.SIMCONNECT_OBJECT_ID_USER, EVENTS.TRUE_AIRSPEED_CAL_DEC, 0, SIMCONNECT_DATA_SET_FLAG.DEFAULT, SIMCONNECT_EVENT_FLAG.DEFAULT);
                        break;
                    case "vaccum1_INC":// vacuum1+
                        simConnect.TransmitClientEvent(SimConnect.SIMCONNECT_OBJECT_ID_USER, EVENTS.GYRO_DRIFT_INC, 0, SIMCONNECT_DATA_SET_FLAG.DEFAULT, SIMCONNECT_EVENT_FLAG.DEFAULT);
                        break;
                    case "vaccum1_DEC":// vacuum1-
                        simConnect.TransmitClientEvent(SimConnect.SIMCONNECT_OBJECT_ID_USER, EVENTS.GYRO_DRIFT_DEC, 0, SIMCONNECT_DATA_SET_FLAG.DEFAULT, SIMCONNECT_EVENT_FLAG.DEFAULT);
                        break;
                    case "vaccum2_INC":// vacuum2+
                        simConnect.TransmitClientEvent(SimConnect.SIMCONNECT_OBJECT_ID_USER, EVENTS.HEADING_BUG_INC, 0, SIMCONNECT_DATA_SET_FLAG.DEFAULT, SIMCONNECT_EVENT_FLAG.DEFAULT);
                        break;
                    case "vaccum2_DEC"://vacuum2-
                        simConnect.TransmitClientEvent(SimConnect.SIMCONNECT_OBJECT_ID_USER, EVENTS.HEADING_BUG_DEC, 0, SIMCONNECT_DATA_SET_FLAG.DEFAULT, SIMCONNECT_EVENT_FLAG.DEFAULT);
                        break;
                    case "altimeter_INC"://Altimeter+
                        simConnect.TransmitClientEvent(SimConnect.SIMCONNECT_OBJECT_ID_USER, EVENTS.KOHLSMAN_INC, 0, SIMCONNECT_DATA_SET_FLAG.DEFAULT, SIMCONNECT_EVENT_FLAG.DEFAULT);
                        break;
                    case "altimeter_DEC"://altimeter-
                        simConnect.TransmitClientEvent(SimConnect.SIMCONNECT_OBJECT_ID_USER, EVENTS.KOHLSMAN_DEC, 0, SIMCONNECT_DATA_SET_FLAG.DEFAULT, SIMCONNECT_EVENT_FLAG.DEFAULT);
                        break;
                    case "NAV1_INC":
                        simConnect.TransmitClientEvent(SimConnect.SIMCONNECT_OBJECT_ID_USER, EVENTS.VOR1_OBI_INC, 0, SIMCONNECT_DATA_SET_FLAG.DEFAULT, SIMCONNECT_EVENT_FLAG.DEFAULT);
                        break;
                    case "NAV1_DEC":
                        simConnect.TransmitClientEvent(SimConnect.SIMCONNECT_OBJECT_ID_USER, EVENTS.VOR1_OBI_DEC, 0, SIMCONNECT_DATA_SET_FLAG.DEFAULT, SIMCONNECT_EVENT_FLAG.DEFAULT);
                        break;
                    case "NAV2_INC":
                        simConnect.TransmitClientEvent(SimConnect.SIMCONNECT_OBJECT_ID_USER, EVENTS.VOR2_OBI_INC, 0, SIMCONNECT_DATA_SET_FLAG.DEFAULT, SIMCONNECT_EVENT_FLAG.DEFAULT);
                        break;
                    case "NAV2_DEC":
                        simConnect.TransmitClientEvent(SimConnect.SIMCONNECT_OBJECT_ID_USER, EVENTS.VOR2_OBI_DEC, 0, SIMCONNECT_DATA_SET_FLAG.DEFAULT, SIMCONNECT_EVENT_FLAG.DEFAULT);
                        break;
                    case "ADF_INC":
                        simConnect.TransmitClientEvent(SimConnect.SIMCONNECT_OBJECT_ID_USER, EVENTS.ADF_CARD_INC, 0, SIMCONNECT_DATA_SET_FLAG.DEFAULT, SIMCONNECT_EVENT_FLAG.DEFAULT);
                        break;
                    case "ADF_DEC":
                        simConnect.TransmitClientEvent(SimConnect.SIMCONNECT_OBJECT_ID_USER, EVENTS.ADF_CARD_DEC, 0, SIMCONNECT_DATA_SET_FLAG.DEFAULT, SIMCONNECT_EVENT_FLAG.DEFAULT);
                        break;
                    default:
                        break;
                }
            } catch (Exception ex)
            {
                connectP3d();
                Console.WriteLine(ex.ToString());
            }
           
        }
        #endregion

        /// <summary>
        /// 教员站Task And View界面
        /// </summary>
        public static void simTaskEventID(string eventID)
        {
            try
            {
                switch (eventID)
                {
                    case "SITUATION_RESET"://重载场景
                        simConnect.TransmitClientEvent(SimConnect.SIMCONNECT_OBJECT_ID_USER, EVENTS.SITUATION_RESET, 0, SIMCONNECT_DATA_SET_FLAG.DEFAULT, SIMCONNECT_EVENT_FLAG.DEFAULT);
                        break;
                    case "ELECTRIC_GPU_SWITCH_TOGGLE"://重置电源
                        simConnect.TransmitClientEvent(SimConnect.SIMCONNECT_OBJECT_ID_USER, EVENTS.ELECTRIC_GPU_SWITCH_TOGGLE, 0, SIMCONNECT_DATA_SET_FLAG.DEFAULT, SIMCONNECT_EVENT_FLAG.DEFAULT);
                        break;
                    case "VIEW_MODE":////视角切换 S键
                        simConnect.TransmitClientEvent(SimConnect.SIMCONNECT_OBJECT_ID_USER, EVENTS.VIEW_MODE, 0, SIMCONNECT_DATA_SET_FLAG.DEFAULT, SIMCONNECT_EVENT_FLAG.DEFAULT);
                        break;
                    case "NEXT_SUB_VIEW":////视角切换 A键
                        simConnect.TransmitClientEvent(SimConnect.SIMCONNECT_OBJECT_ID_USER, EVENTS.NEXT_SUB_VIEW, 0, SIMCONNECT_DATA_SET_FLAG.DEFAULT, SIMCONNECT_EVENT_FLAG.DEFAULT);
                        break;
                    case "VIEW_COCKPIT_FORWARD":////F10视角第一视角
                        simConnect.TransmitClientEvent(SimConnect.SIMCONNECT_OBJECT_ID_USER, EVENTS.VIEW_COCKPIT_FORWARD, 0, SIMCONNECT_DATA_SET_FLAG.DEFAULT, SIMCONNECT_EVENT_FLAG.DEFAULT);
                        break;
                    case "VIEW_VIRTUAL_COCKPIT_FORWARD":////F9视角舱内第一视角
                        simConnect.TransmitClientEvent(SimConnect.SIMCONNECT_OBJECT_ID_USER, EVENTS.VIEW_VIRTUAL_COCKPIT_FORWARD, 0, SIMCONNECT_DATA_SET_FLAG.DEFAULT, SIMCONNECT_EVENT_FLAG.DEFAULT);
                        break;
                    default:
                        break;
                }
            }
            catch (Exception ex)
            {
                connectP3d();
                Console.WriteLine(ex.ToString());
            }
        }

        /// <summary>
        /// R22事件触发  点火 GPS500按钮  NAV COM频率加减等
        /// </summary>
        /// <param name="eventID">事件ID</param>
        public static void simR22EventID(string eventID)
        {
            try
            {
                switch(eventID)
                {
                    case "mkr"://MKR
                        simConnect.TransmitClientEvent(SimConnect.SIMCONNECT_OBJECT_ID_USER, EVENTS.MARKER_SOUND_TOGGLE, 0, SIMCONNECT_DATA_SET_FLAG.DEFAULT, SIMCONNECT_EVENT_FLAG.DEFAULT);
                        break;
                    case "Eng_Start"://点火
                        simConnect.TransmitClientEvent(SimConnect.SIMCONNECT_OBJECT_ID_USER, EVENTS.ENGINE_AUTO_START, 0, SIMCONNECT_DATA_SET_FLAG.DEFAULT, SIMCONNECT_EVENT_FLAG.DEFAULT);
                        break;
                    case "Eng_Stop"://熄火
                        simConnect.TransmitClientEvent(SimConnect.SIMCONNECT_OBJECT_ID_USER, EVENTS.ENGINE_AUTO_SHUTDOWN, 0, SIMCONNECT_DATA_SET_FLAG.DEFAULT, SIMCONNECT_EVENT_FLAG.DEFAULT);
                        break;
                    case "GPS500_NRST"://GPS NRST
                        simConnect.TransmitClientEvent(SimConnect.SIMCONNECT_OBJECT_ID_USER, EVENTS.GPS_NEAREST_BUTTON, 0, SIMCONNECT_DATA_SET_FLAG.DEFAULT, SIMCONNECT_EVENT_FLAG.DEFAULT);
                        break;
                    case "GPS500_OBS"://GPS OBS
                        simConnect.TransmitClientEvent(SimConnect.SIMCONNECT_OBJECT_ID_USER, EVENTS.GPS_OBS_BUTTON, 0, SIMCONNECT_DATA_SET_FLAG.DEFAULT, SIMCONNECT_EVENT_FLAG.DEFAULT);
                        break;
                    case "GPS500_MSG"://GPS MSG
                        simConnect.TransmitClientEvent(SimConnect.SIMCONNECT_OBJECT_ID_USER, EVENTS.GPS_MSG_BUTTON, 0, SIMCONNECT_DATA_SET_FLAG.DEFAULT, SIMCONNECT_EVENT_FLAG.DEFAULT);
                        break;
                    case "GPS500_FPL"://GPS FPL
                        simConnect.TransmitClientEvent(SimConnect.SIMCONNECT_OBJECT_ID_USER, EVENTS.GPS_FLIGHTPLAN_BUTTON, 0, SIMCONNECT_DATA_SET_FLAG.DEFAULT, SIMCONNECT_EVENT_FLAG.DEFAULT);
                        break;
                    case "GPS500_TEER"://TERR
                        simConnect.TransmitClientEvent(SimConnect.SIMCONNECT_OBJECT_ID_USER, EVENTS.GPS_TERRAIN_BUTTON, 0, SIMCONNECT_DATA_SET_FLAG.DEFAULT, SIMCONNECT_EVENT_FLAG.DEFAULT);
                        break;
                    case "GPS500_PROC"://PROC
                        simConnect.TransmitClientEvent(SimConnect.SIMCONNECT_OBJECT_ID_USER, EVENTS.GPS_PROCEDURE_BUTTON, 0, SIMCONNECT_DATA_SET_FLAG.DEFAULT, SIMCONNECT_EVENT_FLAG.DEFAULT);
                        break;
                    case "GPS500_ZOOMOUT"://上
                        simConnect.TransmitClientEvent(SimConnect.SIMCONNECT_OBJECT_ID_USER, EVENTS.GPS_ZOOMOUT_BUTTON, 0, SIMCONNECT_DATA_SET_FLAG.DEFAULT, SIMCONNECT_EVENT_FLAG.DEFAULT);
                        break;
                    case "GPS500_ZOOMIN"://下
                        simConnect.TransmitClientEvent(SimConnect.SIMCONNECT_OBJECT_ID_USER, EVENTS.GPS_ZOOMIN_BUTTON, 0, SIMCONNECT_DATA_SET_FLAG.DEFAULT, SIMCONNECT_EVENT_FLAG.DEFAULT);
                        break;
                    case "GPS500_Diector":// diector
                        simConnect.TransmitClientEvent(SimConnect.SIMCONNECT_OBJECT_ID_USER, EVENTS.GPS_DIRECTTO_BUTTON, 0, SIMCONNECT_DATA_SET_FLAG.DEFAULT, SIMCONNECT_EVENT_FLAG.DEFAULT);
                        break;
                    case "GPS500_MENU"://MENU
                        simConnect.TransmitClientEvent(SimConnect.SIMCONNECT_OBJECT_ID_USER, EVENTS.GPS_MENU_BUTTON, 0, SIMCONNECT_DATA_SET_FLAG.DEFAULT, SIMCONNECT_EVENT_FLAG.DEFAULT);
                        break;
                    case "GPS500_CLR"://CLR
                        simConnect.TransmitClientEvent(SimConnect.SIMCONNECT_OBJECT_ID_USER, EVENTS.GPS_CLEAR_BUTTON, 0, SIMCONNECT_DATA_SET_FLAG.DEFAULT, SIMCONNECT_EVENT_FLAG.DEFAULT);
                        break;
                    case "GPS500_ENT"://ENT
                        simConnect.TransmitClientEvent(SimConnect.SIMCONNECT_OBJECT_ID_USER, EVENTS.GPS_ENTER_BUTTON, 0, SIMCONNECT_DATA_SET_FLAG.DEFAULT, SIMCONNECT_EVENT_FLAG.DEFAULT);
                        break;
                    case "GPS500_PUSHCRSH"://PUSH CRSR
                        simConnect.TransmitClientEvent(SimConnect.SIMCONNECT_OBJECT_ID_USER, EVENTS.GPS_CURSOR_BUTTON, 0, SIMCONNECT_DATA_SET_FLAG.DEFAULT, SIMCONNECT_EVENT_FLAG.DEFAULT);
                        break;
                    case "GPS500_GROUPDEC"://外圈左
                        simConnect.TransmitClientEvent(SimConnect.SIMCONNECT_OBJECT_ID_USER, EVENTS.GPS_GROUP_KNOB_DEC, 0, SIMCONNECT_DATA_SET_FLAG.DEFAULT, SIMCONNECT_EVENT_FLAG.DEFAULT);
                        break;
                    case "GPS500_GROUPINC"://外圈右
                        simConnect.TransmitClientEvent(SimConnect.SIMCONNECT_OBJECT_ID_USER, EVENTS.GPS_GROUP_KNOB_INC, 0, SIMCONNECT_DATA_SET_FLAG.DEFAULT, SIMCONNECT_EVENT_FLAG.DEFAULT);
                        break;
                    case "GPS500_PAGEDEC"://内圈左
                        simConnect.TransmitClientEvent(SimConnect.SIMCONNECT_OBJECT_ID_USER, EVENTS.GPS_PAGE_KNOB_DEC, 0, SIMCONNECT_DATA_SET_FLAG.DEFAULT, SIMCONNECT_EVENT_FLAG.DEFAULT);
                        break;
                    case "GPS500_PAGEINC"://内圈右
                        simConnect.TransmitClientEvent(SimConnect.SIMCONNECT_OBJECT_ID_USER, EVENTS.GPS_PAGE_KNOB_INC, 0, SIMCONNECT_DATA_SET_FLAG.DEFAULT, SIMCONNECT_EVENT_FLAG.DEFAULT);
                        break;
                    case "COMNAV1"://COM NAV 频率加减
                        simConnect.TransmitClientEvent(SimConnect.SIMCONNECT_OBJECT_ID_USER, EVENTS.COMNAV1, 0, SIMCONNECT_DATA_SET_FLAG.DEFAULT, SIMCONNECT_EVENT_FLAG.DEFAULT);
                        break;
                    case "COMNAV2":
                        simConnect.TransmitClientEvent(SimConnect.SIMCONNECT_OBJECT_ID_USER, EVENTS.COMNAV2, 0, SIMCONNECT_DATA_SET_FLAG.DEFAULT, SIMCONNECT_EVENT_FLAG.DEFAULT);
                        break;
                    case "COMNAV3":
                        simConnect.TransmitClientEvent(SimConnect.SIMCONNECT_OBJECT_ID_USER, EVENTS.COMNAV3, 0, SIMCONNECT_DATA_SET_FLAG.DEFAULT, SIMCONNECT_EVENT_FLAG.DEFAULT);
                        break;
                    case "COMNAV4":
                        simConnect.TransmitClientEvent(SimConnect.SIMCONNECT_OBJECT_ID_USER, EVENTS.COMNAV4, 0, SIMCONNECT_DATA_SET_FLAG.DEFAULT, SIMCONNECT_EVENT_FLAG.DEFAULT);
                        break;
                    default:
                        break;
                }
            }
            catch (Exception ex)
            {
                connectP3d();
                Console.WriteLine(ex.ToString());
            }
        }
    }
}
